home *** CD-ROM | disk | FTP | other *** search
/ Greenhouse Effect Detection Expriment / NASA Greenhouse Effect Detection Expriment 1992 - Disc 2.iso / software / dos / cdf22pc / src / tools / utility.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-27  |  21.9 KB  |  988 lines

  1. /******************************************************************************
  2. *
  3. *  NSSDC/CDF                        Utility functions.
  4. *
  5. *  Version 2.0, 27-Feb-92, ST Systems (STX)
  6. *
  7. *  Modification history:
  8. *
  9. *   V1.0  29-Jan-91, D Grogan    Original version (for CDF V2.0).
  10. *             H Leckner
  11. *   V1.1  15-Mar-91, H Leckner    Added PF keys to cause exit from function.
  12. *   V1.2  25-Jun-91, H Leckner    Fix for Iris console.  Removed 'prtext'.
  13. *             J Love
  14. *   V1.3  28-Jun-91, J Love    TRUE/FALSE.  Changed 'string_count' so it
  15. *                doesn't execute NULL (whatever that does).
  16. *   V2.0  27-Feb-92, J Love    Modified for IBM-PC port.  CDF V2.2.
  17. *             H Leckner
  18. *
  19. ******************************************************************************/
  20.  
  21. /*
  22.  *    MODULE:     UTILITY.C  for WFL
  23.  */
  24.  
  25. /*
  26.  *  MODS to UTILITY.C --
  27.  *  Reworked, enhanced input_field() and get_input()
  28.  *
  29.  *  2 new functions added to UTILITY.C --
  30.  *    For getting and setting the physical cursor.
  31.  *
  32.  *  2 new functions added to UTILITY.C --
  33.  *    For set-save the menu-bar row and column position.
  34.  *
  35.  *  Comparable functions added to the SMG_GLUE_C.C under-layer.
  36.  *  Dan Grogan, October 1988.
  37.  */
  38.  
  39. #include <string.h>
  40.  
  41. #include "wfl.h"
  42. #include "cdfdist.h"
  43. #include "kb_def.h"   
  44. #include "utility.h"
  45.  
  46. void redraw_screen ()
  47.  
  48. /*
  49.  *  This function refreshes the screen identified by pbid.
  50.  */
  51.                              /*CodeRef-mark*/
  52. {
  53.     repaint_screen();
  54. }
  55.  
  56.                              /*CodeRef-mark*/
  57.  
  58. void place_cursor_abs (vid, row, col)
  59.     WINDOWid     vid;
  60.     int         row;
  61.     int         col;
  62.  
  63.  /*
  64.   *     NOT SURE OF THIS ONE (dg).  Absolute or relative cursor?
  65.   */
  66.                              /*CodeRef-mark*/
  67. {
  68.     set_cursor_abs (vid, row, col);
  69. }
  70.  
  71.  
  72.  
  73.                              /*CodeRef-mark*/
  74.  
  75. void place_cursor_rel (vid, num_rows, num_cols)
  76.     WINDOWid     vid;
  77.     int         num_rows;
  78.     int         num_cols;
  79.  
  80.  /*
  81.   *     NOT SURE OF THIS ONE (dg).  not sure it works.
  82.   */
  83.                               /*CodeRef-mark*/
  84. {
  85.     set_cursor_rel (vid, num_rows, num_cols);
  86. }
  87.  
  88.  
  89.  
  90.                                 /*CodeRef-mark*/
  91.  
  92.  
  93. #if defined(vms)
  94. void get_input(value, keyWas)
  95. #else
  96. void get_input(id, value, keyWas)
  97.     WINDOWid        id;
  98. #endif
  99.  
  100. /*id = int    vdid;      Current window  for curses UNIX */
  101.  
  102.     char            *value;   /* Actual scancode value of the key */
  103.                   /* struck by user    -- output */
  104.     int        *keyWas;   /* Filtered key code for WFL,  */
  105.                   /* eg, ALPHA, PF1, SELECT, etc. */
  106. /*
  107.  *      SINGLE-POINT-OF-INPUT for all WFL via call to read_input().
  108.  *      All keys are filtered first in this function.
  109.  */
  110.                              /*CodeRef-mark*/
  111. {
  112.     int    scancode;
  113. #if defined(vms)
  114.     read_input (&scancode);
  115. #else
  116.     read_input (id, &scancode);
  117. #endif
  118.     *value = (char)scancode;
  119.  
  120. /* Check for ALPHA Key */
  121.     if    ((scancode >=  65  &&  scancode <=  90)  ||
  122.          (scancode >=  97  &&  scancode <= 122))
  123.          *keyWas = ALPHA;
  124.  
  125. /* Check for NUMERIC Key */
  126.     else if     (scancode >=  48  &&  scancode <=  57)
  127.          *keyWas = NUMERIC;
  128.  
  129. /* Check for SPECIAL CHAR Key */
  130.     else if    ((scancode >=  33 && scancode <=  47)  ||
  131.          (scancode >=  58 && scancode <=  64)  ||
  132.          (scancode >=  91 && scancode <=  96)  ||
  133.          (scancode >= 123 && scancode <= 126))
  134.          *keyWas = SPECIAL;
  135.  
  136. /* Check for SPACE Key */
  137.     else if    (scancode == KB_SPACE)
  138.          *keyWas = SPACECHAR;
  139.  
  140. /* Check for DELETECHAR Key */
  141.     else if     ((scancode == KB_DELETE) ||
  142.           (scancode == KBF_BACKSPACE))
  143.          *keyWas = DELETECHAR;
  144. #if defined(__MSDOS__)
  145.     else if (scancode == KB_DEL_AND_STAY)
  146.          *keyWas = DELSTAY;
  147. #endif
  148.  
  149.     else if (scancode == KBM_ENTER)
  150.          *keyWas = KBM_SELECT;
  151.  
  152.     else if (scancode == KBF_ENTER)
  153.          *keyWas = KBF_NEXTFIELD;
  154.  
  155. /*  major mods following <dan> */
  156. /* Check for any other valid user defined menu or form keystroke */
  157.  
  158.     else if    (
  159.                 /* pass all keypad keys */
  160.          ( (scancode >= KB_PF1) && (scancode <= KB_PAD_DOT) ) ||
  161.  
  162.          (scancode == KB_CONTEXT_HELP) ||
  163.  
  164.          (scancode == KBM_QUIT) ||
  165.          (scancode == KBM_UP) ||
  166.          (scancode == KBM_DOWN) ||
  167.          (scancode == KBM_LEFT) ||
  168.          (scancode == KBM_RIGHT) ||
  169.          (scancode == KBM_SELECT) ||
  170.          (scancode == KBM_EXIT) ||
  171.          (scancode == KBM_BACK) ||
  172.          (scancode == KBM_HELP) ||
  173.          (scancode == KBM_PREVSCRN) || (scancode == KBM_prevscrn) ||
  174.          (scancode == KBM_NEXTSCRN) || (scancode == KBM_nextscrn) ||
  175.          (scancode == KBM_POPUP) ||
  176.          (scancode == KBM_ACTION) ||
  177.  
  178.          (scancode == KBF_QUIT) ||
  179.          (scancode == KBF_HELP) ||
  180.          (scancode == KBF_TOGGLE_INSERT) ||
  181. /*         (scancode == KBF_MOVE_SOL) || */
  182.          (scancode == KBF_MOVE_EOL) ||
  183.          (scancode == KBF_MOVE_SOL_ALT) ||
  184.          (scancode == KBF_MOVE_EOL_ALT) ||
  185.          (scancode == KBF_DEL_TO_EOL) ||
  186.          (scancode == KBF_DEL_TO_SOL) ||
  187.          (scancode == KBF_UP) ||
  188.          (scancode == KBF_DOWN) ||
  189.          (scancode == KBF_LEFT) ||
  190.          (scancode == KBF_RIGHT) ||
  191.          (scancode == KBF_EXIT) ||
  192.          (scancode == KBF_NEXTFIELD) ||
  193.          (scancode == KBF_PREVFIELD) ||
  194.          (scancode == KBF_POPUP) ||
  195.          (scancode == KBF_ACTION)
  196.                         )
  197.          *keyWas = scancode;
  198.  
  199.  
  200. /* Check for REDRAW Key */
  201.  
  202.     else if    (scancode == KB_REDRAW)
  203.          *keyWas = REDRAW;
  204.  
  205. /* UNDEFINED Key */
  206.  
  207.     else
  208.         {
  209. /*
  210.  *      printf ("\n (UTILITY/get_input) : Undefined Key %3ld", scancode);
  211.  */
  212.         *keyWas = ERROR;
  213.         }
  214.  
  215. }  /* end get_input */
  216.  
  217.  
  218.  
  219.                              /*CodeRef-mark*/
  220.  
  221.  
  222.  
  223.                         /*CodeRef-mark*/
  224. void fieldValToString(data, data_type, string_data, field_len)
  225.     int    *data;
  226.     int      data_type;
  227.     char        *string_data; 
  228.     int     field_len;
  229. /*
  230. Convert the field value held in *data to a string according to its 
  231. data_type.
  232. */
  233.                         /*CodeRef-mark*/
  234. {
  235.     /*union ALLTYPES overlay;*/
  236.  
  237.     switch (data_type)
  238.        {
  239.         case DT_CHAR:
  240.             sprintf (string_data, "%c", *data);
  241.             break;
  242.         case DT_STRING:
  243.             strncpy (string_data, (char *) data, field_len);
  244.             break;
  245.         case DT_SHORTINT:
  246.             sprintf (string_data, "%d", *data);
  247.             break;
  248.         case DT_LONGINT:
  249.             sprintf (string_data, "%ld", *data);
  250.             break;
  251.         case DT_FLOAT:
  252.             sprintf (string_data, "%f", *data);
  253.             break;
  254.         case DT_DOUBLE:
  255.             sprintf (string_data, "%lf", *data);
  256.             break;
  257.  
  258.         default:
  259.             fprintf(stderr,
  260.             "\n<UTILITY-fieldValToString> Bad data-type %ld",
  261.                 data_type);
  262.             break;
  263.        }
  264. }  /* end fieldValToString */
  265.  
  266.  
  267.  
  268.                         /*CodeRef-mark*/
  269. int stringToFieldVal(data, data_type, string_data, field_len)
  270.  
  271.     int        *data;
  272.     int      data_type;
  273.     char        *string_data;
  274.     int     field_len;
  275. /*
  276. Convert the *string_data to a a field value in *data according to its 
  277. data_type.
  278. */
  279.                         /*CodeRef-mark*/
  280. {
  281.     int status = FALSE;
  282.     union ALLTYPES overlay;
  283.  
  284.        switch (data_type)
  285.           {
  286.         case DT_CHAR:
  287.             status = sscanf (string_data, "%c", data);
  288.             break;
  289.  
  290.         case DT_STRING:
  291.             strncpy ((char *) data, string_data, field_len);
  292.             status = TRUE;
  293.             break;
  294.         case DT_SHORTINT:
  295.             status = sscanf (string_data, "%d", data);
  296.             break;
  297.         case DT_LONGINT:
  298.             status = sscanf (string_data, "%ld", data);
  299.             break;
  300.         case DT_FLOAT:
  301.             status = sscanf (string_data, "%f", data);
  302.             break;
  303.  
  304.         case DT_DOUBLE:
  305.             status = sscanf (string_data, "%lf", &overlay.real8);
  306.             memmove (data, &overlay.byte[0], 8);
  307.             break;
  308.  
  309.         default:
  310.             fprintf(stderr,
  311.             "\n<UTILITY-stringToFieldVal> Bad data-type %ld",
  312.                 data_type);
  313.             break;
  314.           }
  315.     return (status);
  316.  
  317. }  /* end stringToFieldVal */
  318.  
  319.  
  320.                              /*CodeRef-mark*/
  321.  
  322. void input_field (vid, field, fieldRow, fieldCol, len, returnKey)
  323.     WINDOWid    vid;
  324.     char         field[];
  325.     int        fieldRow;
  326.     int        fieldCol;
  327.     int        len;
  328.     int        *returnKey;
  329.  
  330.  
  331. /*
  332.  *  This function controls the input of data in a field of a form.
  333.  *
  334.  *  All keyboard input passes first through the get_input function
  335.  *  where it is filtered for illegal characters.
  336.  *  get_input returns two items to this function:
  337.  *    inChar, the numeric value (scancode) of the key that was pressed,
  338.  *    and keyWas, the coded signal that determines how input_field
  339.  *    will responds to the input.
  340.  *  The coded value keyWas is assigned to *returnKey.
  341.  */
  342.                              /*CodeRef-mark*/
  343. {
  344.     static long    insertMode = FALSE; /* default - Overwrite mode */
  345.     /*long         curCol;*/
  346.     char        inChar;
  347.     int    keyWas;
  348.     int    done;
  349.     int    erase_mode;
  350.     int    video_type;
  351.     int    /*i,*/ j /*,k*/ ;
  352.     char        tempField[81];
  353.     long        cursorAt;
  354.     long         endAt;
  355.     long        tailLength;
  356.     long        cursorCol;
  357.     int        last_valid; /* last valid character to delete, depends                         on KEYSTROKE */
  358.     /*char        saveChar;*/
  359.             /* Copy field to tempField, replacing all
  360.              * nulls with blanks.
  361.              */
  362.     for (j=0; j<len; j++)
  363.         {
  364.         if (field[j] != '\0')
  365.         tempField[j] = field[j];
  366.         else
  367.         tempField[j] = ' ';
  368.         }
  369.  
  370.         /* Modes for the display of field */
  371.     erase_mode = FALSE;
  372.     video_type = REVERSE;
  373.  
  374.         /* Put real cursor at start of the field */
  375.     place_cursor_abs (vid, fieldRow, fieldCol);
  376.  
  377.         /* Logical position of the cursor in the buffer
  378.          * tempField is cursorAt; the end of the line is endAt.
  379.          */
  380.     cursorAt = 0;
  381.     endAt = len -1;
  382.  
  383.     done  = FALSE;
  384.  
  385.     while (!done)
  386.         {
  387. /*
  388. Use current window to read from
  389. */
  390. #ifdef vms
  391.         get_input (&inChar, &keyWas);
  392. #endif
  393. #if defined(unix) | defined(__MSDOS__)
  394.         get_input (vid, &inChar, &keyWas);
  395. #endif
  396.         /* inChar now holds the input character;
  397.          * keyWas tells us what kind of character.
  398.          */
  399.  
  400.         switch (keyWas)
  401.         {
  402.         case ALPHA:           /* These are the regular chars */
  403.         case NUMERIC:
  404.         case SPECIAL:      /* Special as in ! @ # $ % ^, etc. */
  405.         case SPACECHAR:
  406.  
  407.           if (insertMode)  /* We'll push all characters
  408.                     * right starting at the cursor.
  409.                     * Any char pushed off the end is lost.
  410.                     */
  411.              {
  412.  
  413.             /* Push characters to the right;
  414.              * (Or, rather, pull them from the end.)
  415.              */
  416.              for (j=endAt; j>cursorAt; j--)
  417.             tempField[j] = tempField[j-1];
  418.  
  419.             /* put input character in the buffer at cursor */
  420.              tempField[cursorAt] = inChar;
  421.  
  422.             /* Re-figure items for put_chars
  423.              * tailLength is number of chars from cursor to end.
  424.              * cursorCol is real cursor's position.
  425.              */
  426.              tailLength = endAt -cursorAt +1;
  427.              cursorCol = fieldCol +cursorAt;
  428.  
  429.             /* re-write the tempField tail to the screen */
  430.              put_chars (vid, &tempField[cursorAt],
  431.                 tailLength, fieldRow, cursorCol,
  432.                 erase_mode, video_type);
  433.  
  434.              if (cursorAt < endAt)
  435.             cursorAt++;
  436.  
  437.             /* put the real cursor on the new current column */
  438.              place_cursor_abs (vid, fieldRow, fieldCol +cursorAt);
  439.  
  440.              }  /* end insert modee */
  441.  
  442.  
  443.           else  /* not insert mode (overwrite mode) */
  444.              {
  445.             /* put character in the tempField buffer */
  446.              tempField[cursorAt] = inChar;
  447.  
  448.             /* Re-figure items for put_chars
  449.              * Tail is just a single character in overwrite mode.
  450.              * cursorCol is real cursor's position.
  451.              */
  452.              tailLength = 1;
  453.              cursorCol = fieldCol +cursorAt;
  454.  
  455.             /* re-write the tempField tail to the screen */
  456.              put_chars (vid, &tempField[cursorAt],
  457.                 tailLength, fieldRow, cursorCol,
  458.                 erase_mode, video_type);
  459.  
  460.              if (cursorAt < endAt)
  461.             cursorAt++;
  462.  
  463.             /* put the real cursor on the new current column */
  464.              place_cursor_abs (vid, fieldRow, fieldCol +cursorAt);
  465.  
  466.              }   /* end not insert mode (overwrite mode) */
  467.  
  468.              /* end of character or number input */
  469.              break;
  470.  
  471.  
  472.         case KBF_DEL_TO_SOL:        /* delete left of cursor to start */
  473.  
  474.              while
  475.             (cursorAt > 0)  /* can't delete left of field */
  476.                {
  477.                 /* Move logical cursor to the doomed character
  478.                  */
  479.             cursorAt--;
  480.  
  481.                 /* shift chars left in buffer starting at
  482.                  * cursorAt +1
  483.                  */
  484.             for (j=cursorAt; j<endAt; j++)
  485.                 tempField[j] = tempField[j+1];
  486.  
  487.                 /* Hang a blank on the end to replace
  488.                  * the deleted character, so length
  489.                  * remains correct and the blanks
  490.                  * fill in the line from the right.
  491.                  */
  492.             tempField[endAt] = ' ';
  493.  
  494.               }  /* end while cursorAt > 0 */
  495.  
  496.                 /* re-figure the tail of the line,
  497.                  * from cursorAt to endAt.
  498.                  */
  499.             tailLength = endAt -cursorAt +1;
  500.             cursorCol = fieldCol +cursorAt;
  501.  
  502.                   /* re-write the tempField tail to the screen */
  503.             put_chars (vid, &tempField[cursorAt],
  504.                    tailLength, fieldRow, cursorCol,
  505.                    erase_mode, video_type);
  506.  
  507.                   /* put the real cursor on the current column */
  508.             place_cursor_abs (vid, fieldRow, fieldCol +cursorAt);
  509.  
  510.             break; /* end KBF_DEL_TO_SOL case */
  511.  
  512.  
  513.  
  514.         case DELETECHAR:    /* delete left of cursor */
  515.              last_valid = 1;
  516. #if defined(__MSDOS__)
  517.         case DELSTAY:
  518.              if(keyWas == DELSTAY)last_valid = 0;
  519. #endif
  520.              if (cursorAt >= last_valid)
  521.             {
  522.                 /* Move logical cursor to the doomed character
  523.                  */
  524.             cursorAt--;
  525. #if defined(__MSDOS__)
  526.             if(keyWas == DELSTAY)cursorAt++;
  527. #endif
  528.  
  529.  
  530.                 /* shift chars left in buffer starting at
  531.                  * cursorAt +1
  532.                  */
  533.             for (j=cursorAt; j<endAt; j++)
  534.                 tempField[j] = tempField[j+1];
  535.  
  536.                 /* Hang a blank on the end to replace
  537.                  * the deleted character, so length
  538.                  * remains correct and the blanks
  539.                  * fill in the line from the right.
  540.                  */
  541.             tempField[endAt] = ' ';
  542.  
  543.                 /* re-figure the tail of the line,
  544.                  * from cursorAt to endAt.
  545.                  */
  546.             tailLength = endAt -cursorAt +1;
  547.             cursorCol = fieldCol +cursorAt;
  548.  
  549.                   /* re-write the tempField tail to the screen */
  550.             put_chars (vid, &tempField[cursorAt],
  551.                    tailLength, fieldRow, cursorCol,
  552.                    erase_mode, video_type);
  553.                   /* put the real cursor on the current column */
  554.             place_cursor_abs (vid, fieldRow, fieldCol +cursorAt);
  555.  
  556.  
  557.             }  /* end if cursorAt > 0 */
  558.  
  559.             break; /* end DELETECHAR case */
  560.  
  561.  
  562.         case KBF_DEL_TO_EOL:    /* delete from cursor to end-of-line */
  563.  
  564.                 /* Make blanks of cursor and all
  565.                  * chars to right of cursor
  566.                  */
  567.             for (j=cursorAt; j<=endAt; j++)
  568.                 tempField[j] = ' ';
  569.                 /* re-figure the tail of the line,
  570.                  * from cursorAt to endAt.
  571.                  */
  572.             tailLength = endAt -cursorAt +1;
  573.             cursorCol = fieldCol +cursorAt;
  574.  
  575.                   /* re-write the tempField tail to the screen */
  576.             put_chars (vid, &tempField[cursorAt],
  577.                    tailLength, fieldRow, cursorCol,
  578.                    erase_mode, video_type);
  579.  
  580.                   /* put the real cursor on the current column */
  581.             place_cursor_abs (vid, fieldRow, fieldCol +cursorAt);
  582.  
  583.             break; /* end KBF_DEL_TO_EOL case */
  584.  
  585.  
  586.         case KBF_TOGGLE_INSERT:     /* toggle between insert &
  587.                          *    overwrite modes
  588.                          */
  589.             if (insertMode) insertMode = FALSE;
  590.             else        insertMode = TRUE;
  591.  
  592.             break;
  593.  
  594. /*        case KBF_MOVE_SOL: */      /* move cursor to start of line */
  595.         case KBF_MOVE_SOL_ALT:
  596.  
  597.             cursorAt = 0;
  598.               /* put the real cursor on the current column */
  599.             place_cursor_abs (vid, fieldRow, fieldCol +cursorAt);
  600.  
  601.             break;
  602.  
  603.  
  604.         case KBF_MOVE_EOL:     /* move cursor to end of line */
  605.         case KBF_MOVE_EOL_ALT:
  606.  
  607.                        /* That is, move the cursor
  608.                     * to the right of the last
  609.                     * non-blank character.
  610.                     */
  611.             cursorAt = endAt;
  612.             while ( (tempField[cursorAt] == ' ') &&
  613.                 (cursorAt != 0) )
  614.             cursorAt--;
  615.  
  616.             if (cursorAt != endAt)
  617.             cursorAt++;
  618.  
  619.               /* put the real cursor on the current column */
  620.             place_cursor_abs (vid, fieldRow, fieldCol +cursorAt);
  621.  
  622.             break;
  623.  
  624.  
  625.         case KBF_RIGHT:    /* move cursor right, non-destructive.
  626.                     * Will wrap-around the end of line.
  627.                     */
  628.              if (cursorAt < endAt)
  629.             cursorAt++;
  630.              else /* cursorAt == endAt, so wrap around to 0 */
  631.             cursorAt = 0;
  632.  
  633.                    /* put the real cursor on the current column */
  634.              place_cursor_abs (vid, fieldRow, fieldCol +cursorAt);
  635.  
  636.              break;
  637.  
  638.         case KBF_LEFT:     /* move cursor left, non-destructive. 
  639.                     * Will wrap-around the start of line.
  640.                     */
  641.              if (cursorAt > 0)
  642.             cursorAt--;
  643.              else /* cursorAt == 0, so wrap around to endAt */
  644.             {
  645.             cursorAt = endAt;
  646.  
  647.                 /* Put logical cursor at last
  648.                  * significant character plus 1.
  649.                  */
  650.             while ( (tempField[cursorAt] == ' ') &&
  651.                 (cursorAt != 0) ) 
  652.             cursorAt--;
  653.  
  654.             if (cursorAt != endAt)
  655.                 cursorAt++;
  656.             }
  657.  
  658.                   /* put the real cursor on the current column */
  659.              place_cursor_abs (vid, fieldRow, fieldCol +cursorAt);
  660.  
  661.              break;
  662.  
  663.         case REDRAW:
  664.              redraw_screen();
  665.              break;
  666.  
  667.                 /*
  668.                  *  These keys cause EXIT of the function (done becomes TRUE)
  669.          */
  670.         case KB_CONTEXT_HELP:
  671.         case KBM_QUIT:      /* quit the program */
  672.         case KBF_HELP:
  673.                 case KBF_DOWN:
  674.         case KBF_NEXTFIELD:            
  675.                 case KBF_UP:
  676.         case KBF_PREVFIELD:
  677.         case KBF_EXIT:
  678.         case KBF_POPUP:
  679.         case KBF_ACTION:
  680.         case KB_PAD0:
  681.         case KB_PAD1:
  682.         case KB_PAD2:
  683.         case KB_PAD3:
  684.         case KB_PAD4:
  685.         case KB_PAD5:
  686.         case KB_PAD6:
  687.         case KB_PAD7:
  688.         case KB_PAD_ENTER:
  689.         case KB_PAD_COMMA:
  690.         case KB_PAD_DOT:
  691.         case KB_PF1:                    /* V1.1 */
  692.         case KB_PF2:                    /* V1.1 */
  693.         case KB_PF3:                    /* V1.1 */
  694.         case KB_PF4:                    /* V1.1 */
  695.  
  696.              done = TRUE;
  697.              break;
  698.  
  699.         }   /* switch (keyWas) */
  700.  
  701.     }  /* end while !done */
  702.  
  703.     *returnKey = keyWas;
  704.  
  705.         /* Restore the original data field to the contents 
  706.          * of tempField, except replace trailing blanks with NULLs.
  707.          */
  708.         for (j=0; j<len; j++)
  709.         {
  710.         field[j] = tempField[j];
  711.         }
  712.         /* back-fill trailing blanks with NULLs */
  713.     j = len-1;
  714.         while ( (field[j] == ' ') && (j >= 0) )
  715.         {
  716.         field[j] = '\0';
  717.         j--;
  718.         }
  719.  
  720.  
  721. }  /* end input_field */
  722.  
  723.  
  724.  
  725.                              /*CodeRef-mark*/
  726.  
  727. void highlight_on ( vid, row, col, num_rows, num_cols)
  728.     WINDOWid     vid;
  729.     int         row;
  730.     int         col;
  731.     int         num_rows;
  732.     int         num_cols;
  733.  
  734. /*  
  735.  *   Turn reverse-video on.
  736.  */
  737.                              /*CodeRef-mark*/
  738. {
  739. #ifdef vms
  740.     int on = 2;
  741. #endif
  742. #if defined(unix) | defined (__MSDOS__)
  743.     int on = REVERSE;
  744. #endif
  745.         change_rendition(vid, row, col, num_rows, num_cols, on);
  746. }
  747.  
  748.  
  749.                              /*CodeRef-mark*/
  750.  
  751. void highlight_off (vid, row, col, num_rows, num_cols)
  752.     WINDOWid     vid;
  753.     int         row;
  754.     int         col;
  755.     int         num_rows;
  756.     int         num_cols;
  757.  
  758. /*  
  759.  *   Turn reverse-video off.
  760.  */
  761.                              /*CodeRef-mark*/
  762. {
  763.     long off = 0;
  764.     change_rendition(vid, row, col, num_rows, num_cols, off);
  765. }
  766.  
  767.  
  768.  
  769.                              /*CodeRef-mark*/
  770.  
  771. void highlight_selection (window_ptr, element_ptr, old_element, new_element)
  772.     struct  window_struct      *window_ptr;
  773.     struct  menu_element_struct  *element_ptr[];
  774.     int            old_element;
  775.     int            new_element;
  776.  
  777. /*
  778.  *  Highlight (reverse video) a selection in a menu.
  779.  */
  780.                                                      /*CodeRef-mark*/
  781. {
  782.     int            num_rows;
  783.     int            num_cols;
  784.     
  785.     num_cols = strlen((*element_ptr[old_element]).label);
  786.     num_rows = 1;
  787.     highlight_off((*window_ptr).wind_id, 
  788.               (*element_ptr[old_element]).start_row,
  789.               (*element_ptr[old_element]).start_col,
  790.             num_rows, num_cols);
  791.     num_cols = strlen((*element_ptr[new_element]).label);
  792.     num_rows = 1;
  793.     highlight_on((*window_ptr).wind_id, 
  794.               (*element_ptr[new_element]).start_row,
  795.              (*element_ptr[new_element]).start_col,
  796.                num_rows, num_cols);
  797. }    /* end highlight_selection */
  798.  
  799.  
  800.                                                      /*CodeRef-mark*/
  801.  
  802.     /*
  803.      *    Cursor position functions
  804.       */
  805.  
  806.  
  807. void get_cursor_pos (vid, row, col)
  808.     WINDOWid      vid;
  809.     int         *row;
  810.     int         *col;
  811.  
  812.  /*
  813.   *     NOT SURE OF THIS ONE (dg).  Absolute or relative cursor?
  814.   */
  815.                                                       /*CodeRef-mark*/
  816. {
  817.     return_cursor_pos (vid, row, col);
  818. }
  819.  
  820.  
  821.  
  822.  
  823.                                                      /*CodeRef-mark*/
  824.  
  825.  
  826. void get_physical_cursor_pos (row, col)
  827.     int              *row;
  828.     int             *col;
  829. /*
  830.  *  This function gets the absolute row and column coordinates
  831.  *  of the physical cursor.
  832.  */
  833.                             /*CodeRef-mark*/
  834. {
  835.       get_physical_cursor (row, col);
  836. }  /* end get_physical_cursor_pos */
  837.  
  838.  
  839.  
  840.                              /*CodeRef-mark*/
  841. void set_physical_cursor_pos (row, col)
  842.     int               row;
  843.     int              col;
  844.  
  845. /*
  846.  *  This function SETS the absolute row and column coordinates
  847.  *  of the physical cursor.
  848.  */
  849.                              /*CodeRef-mark*/
  850. {
  851.       set_physical_cursor (row, col);
  852. }  /* end set_physical_cursor_pos */
  853.  
  854.  
  855.                            /*CodeRef-mark*/
  856.  
  857. int menu_bar_last_at_row (set_signal)
  858.             int set_signal;
  859.  
  860. /*    This function is for saving and recalling the physical
  861.  *     cursor row coordinate.
  862.  *       If set_signal is TRUE (!= 0) the row is SAVED and the
  863.  *       function returns the saved value.
  864.  *        If set_signal is FALSE(== 0) the row is RECALLED --
  865.  *        the function returns the last saved row index.
  866.  */
  867.                            /*CodeRef-mark*/
  868. {
  869.     static int physical_row = 0;
  870.     if (set_signal)
  871.         physical_row = set_signal;
  872.  
  873.     return (physical_row);
  874. } /* end menu_bar_last_at_row  */
  875.  
  876.                            /*CodeRef-mark*/
  877.  
  878. int menu_bar_last_at_col (set_signal)
  879.             int set_signal;
  880.  
  881. /*    This function is for saving and recalling the physical
  882.  *     cursor column coordinate.
  883.  *       If set_signal is TRUE (!= 0) the column is SAVED and the
  884.  *       function returns the saved value.
  885.  *        If set_signal is FALSE(== 0) the column is RECALLED --
  886.  *        the function returns the last saved column index.
  887.  */
  888.                            /*CodeRef-mark*/
  889. {
  890.     static long physical_col = 0;
  891.     if (set_signal)
  892.         physical_col = set_signal;
  893.  
  894.     return (physical_col);
  895. } /* end menu_bar_last_at_col  */
  896.  
  897.  
  898.  
  899.                              /*CodeRef-mark*/
  900.  
  901.     /*
  902.      *    Utility string functions
  903.      */
  904.  
  905. #if 0
  906. void prtext (output, text, format)
  907.       FILE *output;
  908.       char *text[];
  909.       char *format;
  910.  
  911. /*
  912.  * Print an array of strings (*text[]) to file output using format string.
  913.  * Function iterates on:   fprintf (output, format, text[j]);
  914.  * A null string signals end of the array.
  915.  */
  916.                              /*CodeRef-mark*/
  917. {
  918.    long j, nullstring = 0;
  919.    for (j=0;  text[j][0] != nullstring; j++)
  920.       fprintf (output, format, text[j]);
  921. }
  922. #endif
  923.  
  924.  
  925.                              /*CodeRef-mark*/
  926. int longest_string (text)
  927.            char *text[];
  928.  
  929. /*
  930.  * Function returns the length of the longest string
  931.  * in an array of strings (*text[]).
  932.  * The function iterates strlen() on the list of strings.
  933.  * A null string MUST mark the end of the array of strings.
  934.  */
  935.                              /*CodeRef-mark*/
  936. {
  937.    long j;
  938.    /*char nullstring = 0;*/ /*jtl*/
  939.    int   maxlen = 0L;
  940.  
  941.    for (j=0;  text[j][0] != '\0'; j++)
  942.        if (strlen(text[j]) > maxlen)  maxlen = strlen(text[j]);
  943.    return (maxlen);
  944. }  /* end longest_string */
  945.  
  946.  
  947.                                                      /*CodeRef-mark*/
  948. int string_count (text)
  949.          char *text[];
  950.  
  951. /*
  952.  * Function returns the number of strings 
  953.  * in an array of strings (*text[]).
  954.  * A null string MUST mark the end of the array of strings, 
  955.  * but the null string is not part of the count.
  956.  */
  957.                                                      /*CodeRef-mark*/
  958. {
  959.    int    count = 0L;
  960.  
  961.    for (count=0;  text[count][0] != '\0'; count++);
  962.    return (count);
  963. }  /* end string_count */
  964.  
  965.  
  966.  
  967.  
  968.  
  969. void end_it(text, index)
  970.                  char *text[];
  971.          int    index;
  972.  
  973. {
  974.    char nullstring = 0;
  975.  
  976.    text[index][0] = nullstring;
  977.  
  978. }  /* end end_it*/
  979.  
  980.  
  981.  
  982.  
  983.  
  984.  
  985.  
  986.  
  987.  
  988.